package frank.zou.fit.casestudy.order;

import fit.ColumnFixture;

public class DiscountRulesFixture extends ColumnFixture {

	public Money listPricePerCase;
	public int numberOfCases;
	public boolean isSeasonal;
	public double discountRate;

	/**
	 * required by FIT for specific types
	 */
	public Object parse(String value, Class type) throws Exception {
		if (type == Money.class) {
			return Money.parse(value);
		} else {
			return super.parse(value, type);
		}
	}

	public Money discountPrice() throws Exception {
		WholeSaleOrder order = doOrderCalculation();
		return order.getCalculatedPrice();
	}

	public Money discountAmount() throws Exception {
		WholeSaleOrder order = doOrderCalculation();
		return order.getDiscountedDifference();
	}
	
	public double discountRate() { 
		return -1;
	}

	private WholeSaleOrder doOrderCalculation() throws Exception {
		WholeSaleOrder order = new WholeSaleOrder();
		order.setNumberOfCases(numberOfCases);
		order.setPricePerCase(listPricePerCase);

		if (isSeasonal) {
			order.setProductType(ProductType.SEASONAL);
		} else {
			order.setProductType(ProductType.YEAR_ROUND);
		}

		PricingEngine.applyDiscount(order);
		return order;
	}

}
